class Solution {
public:
    ListNode* EntryNodeOfLoop(ListNode* pHead) {
        if (!pHead)
            return nullptr;
        ListNode* fast = pHead;
        ListNode* slow = pHead;
        int i = 0;
        while (fast != slow || i == 0)
        {
            slow = slow->next;
            if (!slow)
                return nullptr;
            fast = fast->next;
            if (!fast)
                return nullptr;
            fast = fast->next;
            if (!fast)
                return nullptr;
            i++;
        }
        fast = pHead;
        while (fast != slow)
        {
            fast = fast->next;
            slow = slow->next;
        }
        return fast;
    }
};